/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package db;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Bryan
 * Adds a new client type, sub type and loan type
 */
public class AddType extends HttpServlet {

   

    
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
        Connection con = DBConnector.connect();
        String  checkid = null;
        
        try{
        String name = request.getParameter("name");
        String type = request.getParameter("type");
        
            
                PreparedStatement ps = con.prepareStatement
                        ("insert into quicklenddb.type(name,type) values(?,?)");
                
                
                ps.setString(1, name);
                ps.setString(2, type);
             
                
                ps.executeUpdate();
                
               
                response.sendRedirect("TypeServlet");
            
            
        }catch(SQLException e)
        {
            response.sendRedirect("fail.jsp");
            //Logger.getLogger(RegisterServlet.class.getName()).log(Level.SEVERE, null, e);
        }
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
